package com.andatsoft.laisim.asynctask;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;

import com.andatsoft.laisim.config.LaisimConfig;
import com.andatsoft.laisim.service.PlayerService.RepeatMode;
import com.andatsoft.laisim.utils.Common;

public class ConfigSaverTask extends AsyncTask<Void, Void, Void> {
	private Context mContext;

	public ConfigSaverTask(Context c) {
		mContext = c;
	}

	@Override
	protected Void doInBackground(Void... params) {
		SharedPreferences sp = mContext.getSharedPreferences(
				Common.SP_CONFIG_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();

		editor.putBoolean(Common.SP_CONFIG_EQ, LaisimConfig.isEqEnable);
		editor.putBoolean(Common.SP_CONFIG_BASS, LaisimConfig.isBassEnable);
		editor.putBoolean(Common.SP_CONFIG_SHUFFLE, LaisimConfig.isShuffle);
		int repeatMode = LaisimConfig.repeatMode == RepeatMode.NONE ? 0
				: (LaisimConfig.repeatMode == RepeatMode.REPEAT_ONE ? 1 : 2);
		editor.putInt(Common.SP_CONFIG_REPEAT, repeatMode);
		editor.putInt(Common.SP_CONFIG_PLAY_SONG_ID, LaisimConfig.playingSongId);
		editor.putInt(Common.SP_CONFIG_PLAY_SONG_INDEX,
				LaisimConfig.playingSongIndex);
		editor.putInt(Common.SP_CONFIG_CURRENT_DURATION,
				LaisimConfig.currentDuration);
		editor.commit();

		return null;
	}
}
